home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / foo2hp2600-wrapper < prev    next >
Encoding:
Text File  |  2007-03-27  |  15.7 KB  |  691 lines

  1. #!/bin/sh
  2.  
  3. #* Copyright (C) 2005-2006  Rick Richardson
  4. #*
  5. #* This program is free software; you can redistribute it and/or modify
  6. #* it under the terms of the GNU General Public License as published by
  7. #* the Free Software Foundation; either version 2 of the License, or
  8. #* (at your option) any later version.
  9. #*
  10. #* This program is distributed in the hope that it will be useful,
  11. #* but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #* GNU General Public License for more details.
  14. #*
  15. #* You should have received a copy of the GNU General Public License
  16. #* along with this program; if not, write to the Free Software
  17. #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. #*
  19. #* Authors: Rick Richardson <rick.richardson@comcast.net>
  20.  
  21. VERSION='$Id: foo2hp2600-wrapper.in,v 1.43 2006/12/17 16:00:06 rick Exp $'
  22.  
  23. #
  24. # Printer Notes:
  25. #
  26. # hp2600 -
  27. #
  28.  
  29. PROGNAME="$0"
  30. BASENAME=`basename $PROGNAME`
  31. PREFIX=/usr
  32. SHARE=$PREFIX/share/foo2hp
  33.  
  34. #
  35. #    Log the command line, for debugging and problem reports
  36. #
  37. if [ -x /usr/bin/logger ]; then
  38.     logger -t "$BASENAME" -p lpr.info -- "foo2hp2600-wrapper $@" </dev/null
  39. fi
  40.  
  41. usage() {
  42.     cat <<EOF
  43. Usage:
  44.     $BASENAME [options] [ps-file]
  45.  
  46.     Foomatic printer wrapper for the foo2hp2600 printer driver.
  47.     This script reads a Postscript ps-file or standard input
  48.     and converts it to Zenographics ZjStream printer format.
  49.  
  50. Normal Options:
  51. -b bits           Bits per plane (1 or 2) [$BPP]
  52. -c                Print in color (else monochrome)
  53. -d duplex         Duplex code to send to printer [$DUPLEX]
  54.                     1=off, 2=longedge, 3=shortedge
  55. -m media          Media code to send to printer [$MEDIA]
  56.                     1=standard, 2=transparency, 3=glossy, 257=envelope,
  57.                     259=letterhead, 261=thickstock, 262=postcard, 263=labels
  58. -p paper          Paper code [$PAPER]
  59.                     1=letter, 5=legal, 7=executive, 9=A4, 11=A5, 13=B5
  60.                     20=env#10, 27=envDL 28=envC5 34=envB5 37=envMonarch
  61. -n copies         Number of copies [$COPIES]
  62. -r <xres>x<yres>  Set device resolution in pixels/inch [$RES]
  63. -s source         Source code to send to printer [$SOURCE]
  64.                     1=tray2, 2=tray3, 4=manual/tray1, 7=auto
  65.             Code numbers may vary with printer model.
  66. -t                Draft mode.  Every other pixel is white.
  67. -2/-3/-4/-6/-8/-10/-12/-14/-15/-16/-18
  68.                   Print with N-up (requires psutils)
  69. -o orient         For N-up: -op is portrait, -ol is landscape, -os is seascape.
  70.  
  71. Printer Tweaking Options:
  72. -u <xoff>x<yoff>  Set offset of upper left printable in pixels [varies]
  73. -l <xoff>x<yoff>  Set offset of lower right printable in pixels [varies]
  74. -L mask           Send logical clipping values from -u/-l in ZjStream [3]
  75.                   0=no, 1=Y, 2=X, 3=XY
  76. -P                Do not output START_PLANE codes.  May be needed by some
  77.                   monochrome-only printers.
  78. -X padlen         Add extra zero padding to the end of BID segments [16]
  79.  
  80. Color Tweaking Options:
  81. -g gsopts         Additional options to pass to Ghostscript, such as
  82.                   -dDITHERPPI=nnn, etc.  May appear more than once. []
  83. -G profile.icm    Convert profile.icm to a Postscript CRD using icc2ps and
  84.                   adjust colors using the setcolorrendering PS operator.
  85.                   $SHARE/icm/ will be searched for profile.icm.
  86. -I intent         Select profile intent from ICM file [$INTENT]
  87.                   0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute
  88. -G gamma-file.ps  Prepend gamma-file to the Postscript input to perform
  89.                   color correction using the setcolortransfer PS operator.
  90.  
  91. Debugging Options:
  92. -S plane          Output just a single color plane from a color print [all]
  93.                   1=Cyan, 2=Magenta, 3=Yellow, 4=Black
  94. -D lvl            Set Debug level [$DEBUG]
  95. -V                $VERSION
  96. EOF
  97.  
  98.     exit 1
  99. }
  100.  
  101. #
  102. #       Report an error and exit
  103. #
  104. error() {
  105.     echo "$BASENAME: $1" >&2
  106.     exit 1
  107. }
  108.  
  109. dbgcmd() {
  110.     if [ $DEBUG -ge 1 ]; then
  111.         echo "$@" >&2
  112.     fi
  113.     "$@"
  114. }
  115.  
  116. #
  117. # Portable version of 'which'
  118. #
  119. pathfind() {
  120.     if [ "$1" = -p ]; then
  121.     optp=1
  122.     shift
  123.     else
  124.     optp=0
  125.     fi
  126.     OLDIFS="$IFS"
  127.     IFS=:
  128.     for p in $PATH; do
  129.     if [ -x "$p/$*" ]; then
  130.         if [ $optp = 1 ]; then
  131.         echo "$p/$*"
  132.         fi
  133.         IFS="$OLDIFS"
  134.         return 0
  135.     fi
  136.     done
  137.     IFS="$OLDIFS"
  138.     return 1
  139. }
  140.  
  141. #
  142. # Returns true if $1 is 32-bit binary
  143. #
  144. is32() {
  145.     if pathfind file; then
  146.     path=`pathfind -p "$*"`
  147.     is32=`file -L "$path" | grep 32-bit` 
  148.     if [ "$is32" = "" ]; then
  149.         return 1
  150.     else
  151.         return 0
  152.     fi
  153.     else
  154.     return 1
  155.     fi
  156. }
  157.  
  158. #
  159. #    N-up-ify the job.  Requires psnup from psutils package
  160. #
  161. nup() {
  162.     case "$NUP" in
  163.     [2368]|1[0458])
  164.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.3in -p$paper -q
  165.     ;;
  166.     [49]|1[26])
  167.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.5in -p$paper -q
  168.     ;;
  169.     *)
  170.     error "Illegal call to nup()."
  171.     ;;
  172.     esac
  173. }
  174.  
  175. #
  176. #       Process the options
  177. #
  178.  
  179. # Try to use a local copy of GhostScript 8.54, if available.  Otherwise,
  180. # fallback to whatever the Linux distro has installed (usually 7.07)
  181. #
  182. # N.B. := operator used here, when :- would be better, because "ash"
  183. # doesn't have :-
  184. if gs8 -v >/dev/null 2>&1; then
  185.         GSBIN=${GSBIN:-gs8}
  186. else
  187.         GSBIN=${GSBIN:-gs}
  188. fi
  189.  
  190. CMDLINE="$*"
  191. DEBUG=0
  192. DUPLEX=1
  193. BPP=1
  194. COLOR=
  195. COLORMODE=default
  196. QUALITY=1
  197. QUALITY=wts
  198.  
  199. MEDIA=1
  200. COPIES=1
  201. test -r /etc/papersize && PAPER=$(cat /etc/papersize)
  202. test "$PAPER" || PAPER=1
  203. RES=600x600
  204. SOURCE=7
  205. NUP=
  206. CLIP_UL=
  207. CLIP_LR=
  208. CLIP_LOG=
  209. BC=
  210. AIB=
  211. NOPLANES=
  212. COLOR2MONO=
  213. GAMMAFILE=default
  214. INTENT=0
  215. GSOPTS=
  216. EXTRAPAD=
  217. SAVETONER=
  218. NUP_ORIENT=
  219. GSDEV=-sDEVICE=pbmraw
  220. DefaultRGB=sRGB
  221. # What mode to use if the user wants us to pick the "best" mode
  222. case `$GSBIN --version` in
  223. 7*)
  224.     DEFAULTCOLORMODE=10
  225.     ;;
  226. 8.1*)
  227.     # Buggy 8.14/8.15 in Ubuntu
  228.     DEFAULTCOLORMODE=10
  229.     if is32 $GSBIN; then
  230.         GAMMAFILE=km2430_2.icm
  231.     else
  232.         GAMMAFILE=hpclj2600n-0.icm
  233.     fi
  234.     QUALITY=1
  235.     ;;
  236. *)
  237.     DEFAULTCOLORMODE=10
  238.     ;;
  239. esac
  240.  
  241. while getopts "1:23456789o:b:cC:d:g:l:u:L:m:n:p:q:r:s:tABS:D:G:I:PX:Vh?" opt
  242. do
  243.     case $opt in
  244.     b)    BPP="$OPTARG";;
  245.     c)    COLOR=-c;;
  246.     d)    DUPLEX="$OPTARG";;
  247.     g)    GSOPTS="$GSOPTS $OPTARG";;
  248.     m)    MEDIA="$OPTARG";;
  249.     n)    COPIES="$OPTARG";;
  250.     p)    PAPER="$OPTARG";;
  251.     q)    QUALITY="$OPTARG";;
  252.     r)    RES="$OPTARG";;
  253.     s)    SOURCE="$OPTARG";;
  254.     t)    SAVETONER="-t";;
  255.     l)    CLIP_LR="-l $OPTARG";;
  256.     u)    CLIP_UL="-u $OPTARG";;
  257.     L)    CLIP_LOG="-L $OPTARG";;
  258.     A)    AIB=-A;;
  259.     B)    BC=-B;;
  260.     C)    COLORMODE="$OPTARG";;
  261.     S)    COLOR2MONO="-S$OPTARG";;
  262.     D)    DEBUG="$OPTARG";;
  263.     G)    GAMMAFILE="$OPTARG";;
  264.     I)    INTENT="$OPTARG";;
  265.     P)    NOPLANES=-P;;
  266.     X)    EXTRAPAD="-X $OPTARG";;
  267.     [234689])    NUP="$opt";;
  268.     [57])    error "Can't find acceptable layout for $opt-up";;
  269.     1)    case "$OPTARG" in
  270.         [024568])    NUP="1$OPTARG";;
  271.         *)    error "Can't find acceptable layout for 1$OPTARG-up";;
  272.         esac
  273.         ;;
  274.     o)    case "$OPTARG" in
  275.         l*)    NUP_ORIENT=-l;;
  276.         s*)    NUP_ORIENT=-r;;
  277.         p*|*)    NUP_ORIENT=;;
  278.         esac;;
  279.     V)    echo "$VERSION"; foo2hp -V; exit 0;;
  280.     h|\?)
  281.         if [ "$CMDLINE" != "-?" -a "$CMDLINE" != -h ]; then
  282.             echo "Illegal command:"
  283.             echo "    $0 $CMDLINE"
  284.             echo
  285.         fi
  286.         usage;;
  287.     esac
  288. done
  289. shift `expr $OPTIND - 1`
  290.  
  291. #
  292. #    Select the ghostscript device to use
  293. #
  294. case "$BPP" in
  295. 1)    if [ "" = "$COLOR" ]; then
  296.         GSDEV=-sDEVICE=pbmraw
  297.     else
  298.         GSDEV=-sDEVICE=bitcmyk
  299.     fi
  300.     case "$GAMMAFILE" in
  301.     default)
  302.         if is32 $GSBIN; then
  303.         GAMMAFILE=km2430_2.icm
  304.         GAMMAFILE=hpclj2600n-1.icm
  305.         else
  306.         GAMMAFILE=hpclj2600n-0.icm
  307.         fi
  308.         ;;
  309.     none) GAMMAFILE=;;
  310.     esac
  311.     ;;
  312. 2)    if [ "" = "$COLOR" ];
  313.     then
  314.         # GSDEV=-sDEVICE=pgmraw
  315.         # error "2-bpp monochrome is not yet supported"
  316.         GSDEV="-sDEVICE=cups -dcupsColorSpace=3 -dcupsBitsPerColor=2"
  317.         GSDEV="$GSDEV -dcupsColorOrder=2"
  318.     else
  319.         GSDEV="-sDEVICE=cups -dcupsColorSpace=6 -dcupsBitsPerColor=2"
  320.         GSDEV="$GSDEV -dcupsColorOrder=2"
  321.     fi
  322.  
  323.     case "$GAMMAFILE" in
  324.     default) 
  325.         if is32 $GSBIN; then
  326.         GAMMAFILE=km2430_2.icm
  327.         GAMMAFILE=hpclj2600n-1.icm
  328.         else
  329.         GAMMAFILE=
  330.         fi
  331.         ;;
  332.     none) GAMMAFILE=;;
  333.     esac
  334.     ;;
  335. *)    error "Illegal number of bits per plane ($BPP)";;
  336. esac
  337.  
  338. #
  339. case "$QUALITY" in
  340. 0)
  341.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  342.     ;;
  343. 1)
  344.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  345.     ;;
  346. 2)
  347.     GSOPTS="-dMaxBitMap=500000000 $GSOPTS"
  348.     ;;
  349. wts)
  350.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  351.     ;;
  352. esac
  353.  
  354. #
  355. #    Validate media code
  356. #
  357. case "$MEDIA" in
  358. 1|plain)    MEDIA=1;;
  359. 514|preprinted)    MEDIA=514;;
  360. 513|letterhead)    MEDIA=513;;
  361. 2|transparency)    MEDIA=2;;
  362. 515|prepunched)    MEDIA=515;;
  363. 265|labels)    MEDIA=265;;
  364. 260|bond)    MEDIA=260;;
  365. 516|recycled)    MEDIA=516;;
  366. 512|color)    MEDIA=512;;
  367. 276|tough)    MEDIA=276;;
  368. 267|envelope)    MEDIA=267;;
  369. 258|light)    MEDIA=258;;
  370. 262|heavy)    MEDIA=262;;
  371. 261|cardstock)    MEDIA=261;;
  372. 268|lightglossy)    MEDIA=268;;
  373. 269|glossy)    MEDIA=269;;
  374. 270|heavyglossy)    MEDIA=270;;
  375. 277|cover)    MEDIA=277;;
  376. 278|photo)    MEDIA=278;;
  377. [0-9]*)        ;;
  378. *)        error "Unknown media code $MEDIA";;
  379. esac
  380.  
  381. #
  382. #    Validate source (InputSlot) code
  383. #
  384. case "$SOURCE" in
  385. 1|tray2)    SOURCE=1;;
  386. 4|tray1)    SOURCE=4;;
  387. 7|auto)        SOURCE=7;;
  388. [0-9]*)        ;;
  389. *)        error "Unknown source code $SOURCE";;
  390. esac
  391.  
  392. #
  393. #    Validate Duplex code
  394. #
  395. case "$DUPLEX" in
  396. 1|off|none)    DUPLEX=1;;
  397. 2|long*)    DUPLEX=2;;
  398. 3|short*)    DUPLEX=3;;
  399. [0-9]*)        ;;
  400. *)        error "Unknown duplex code $DUPLEX";;
  401. esac
  402.  
  403. #
  404. #    Validate Resolution
  405. #
  406. case "$RES" in
  407. 600x600)    ;;
  408. 1200x600)    ;;
  409. 2400x600)    ;;
  410. *)        error "Illegal resolution $RES";;
  411. esac
  412.  
  413. #
  414. #    Figure out the paper dimensions in pixels/inch, and set the
  415. #    default clipping region.  Unfortunately, this is a trouble
  416. #    area for ZjStream printers.  Various versions of ZjS print
  417. #    engines react differently when asked to print into their
  418. #    unprintable regions.
  419. #
  420. set_clipping() {
  421.     ulx=$1; uly=$2
  422.     lrx=$3; lry=$4
  423.  
  424.     # Set clipping region if it isn't already set
  425.     if [ "$CLIP_UL" = "" ]; then
  426.     case "$RES" in
  427.     600x600)    ulx=`expr $ulx / 2`;;
  428.     2400x600)    ulx=`expr $ulx \* 2`;;
  429.     esac
  430.     CLIP_UL="-u ${ulx}x${uly}"
  431.     fi
  432.     if [ "$CLIP_LR" = "" ]; then
  433.     case "$RES" in
  434.     600x600)    lrx=`expr $lrx / 2`;;
  435.     2400x600)    lrx=`expr $lrx \* 2`;;
  436.     esac
  437.     CLIP_LR="-l ${lrx}x${lry}"
  438.     fi
  439. }
  440.  
  441. case "$PAPER" in
  442. 1|letter)    PAPER=1;    paper=letter;    XDIM="10200"; YDIM="6600"
  443.         set_clipping 172 80    172 80
  444.         ;;
  445. 5|legal)    PAPER=5;    paper=legal;     XDIM="10200"; YDIM="8400"
  446.         set_clipping 172 80    172 80
  447.         ;;
  448. 7|executive)    PAPER=7;    paper=executive; XDIM="8700";  YDIM="6300"
  449.         set_clipping 174 78    174 78
  450.         ;;
  451. 9|a4|A4)    PAPER=9;    paper=a4;        XDIM="9920";  YDIM="7016"
  452.         set_clipping 176 84    176 84
  453.         ;;
  454. 11|a5|A5)    PAPER=11;    paper=a5;        XDIM="6992";  YDIM="4960"
  455.         set_clipping 176 80    176 80
  456.         ;;
  457. 13|b5|B5|b5jis)    PAPER=13;    paper=b5;        XDIM="8598";  YDIM="6070"
  458.         set_clipping 172 83    171 83
  459.         ;;
  460. 20|"env#10")    PAPER=20;    paper=env10;     XDIM="4950";  YDIM="5700"
  461.         set_clipping 171 78    171 78
  462.         ;;
  463. 27|envDL)    PAPER=27;    paper=envDL;     XDIM="5200";  YDIM="5200"
  464.         set_clipping 176 84    176 84
  465.         ;;
  466. 28|envC5)    PAPER=28;    paper=envC5;     XDIM="7650";  YDIM="5408"
  467.         set_clipping 170 80    169 80
  468.         ;;
  469. 34|envB5)    PAPER=34;    paper=envB5;     XDIM="8316";  YDIM="5892"
  470.         set_clipping 174 74    174 74
  471.         ;;
  472. 37|envMonarch)    PAPER=37;    paper=envMonarch;XDIM="4650";  YDIM="4500"
  473.         set_clipping 174 78    173 78
  474.         ;;
  475. *)        error "Unimplemented paper code $PAPER";;
  476. esac
  477. # e.g. /usr/share/ghostscript/7.07/lib/gs_statd.ps
  478. PAPERSIZE="-sPAPERSIZE=$paper";
  479.  
  480. case "$RES" in
  481. 600x600)    XDIM=`expr $XDIM / 2`;;
  482. 1200x600)    ;;
  483. 2400x600)    XDIM=`expr $XDIM \* 2`;;
  484. esac
  485. DIM="${XDIM}x${YDIM}"
  486.  
  487. #
  488. # If there is an argument left, take it as the file to print.
  489. # Else, the input comes from stdin.
  490. #
  491. if [ $# -ge 1 ]; then
  492.     if [ "$LPJOB" = "" ]; then
  493.     : # LPJOB="$1"
  494.     fi
  495.     exec < $1
  496. fi
  497.  
  498. #
  499. # Filter thru psnup if N-up printing has been requested
  500. #
  501. case $NUP in
  502. [234689]|1[024568])    PREFILTER="nup";;
  503. *)            PREFILTER=cat;;
  504. esac
  505.  
  506. #
  507. #    Overload -G.  If the file name ends with ".icm" or ".ICM"
  508. #    then convert the ICC color profile to a Postscript CRD,
  509. #    then prepend it to the users job.  Select the intent
  510. #    using the -I option.
  511. #
  512.  
  513. create_crd() {
  514.     #
  515.     # Create a Postscript CRD
  516.     #
  517.     ICC2PS=$PREFIX/bin/foo2zjs-icc2ps
  518.     if [ -x $ICC2PS ]; then
  519.     case "$GAMMAFILE" in
  520.     none.icm | */none.icm)
  521.         ;;
  522.     *)
  523.         $ICC2PS -o $GAMMAFILE -t$INTENT > $ICCTMP.crd.ps 2>$ICCTMP.log \
  524.         || error "Problem converting .ICM file to Postscript"
  525.         ;;
  526.     esac
  527.         
  528.     cat > $ICCTMP.usecie.ps <<-EOF
  529.         %!PS-Adobe-3.0
  530.         <</UseCIEColor true>>setpagedevice
  531.     EOF
  532.     if [ "$QUALITY" = wts ]; then
  533.         cat >> $ICCTMP.usecie.ps <<-EOF
  534.         << /UseWTS true >> setuserparams
  535.         <<
  536.             /AccurateScreens true
  537.             /HalftoneType 1
  538.             /HalftoneName (Round Dot Screen) cvn
  539.             /SpotFunction { 180 mul cos exch 180 mul cos add 2 div}
  540.             /Frequency 137
  541.             /Angle 37
  542.         >> sethalftone
  543.         EOF
  544.     fi
  545.     cat > $ICCTMP.selcrd.ps <<-EOF
  546.         /Current /ColorRendering findresource setcolorrendering
  547.     EOF
  548.     case "$GAMMAFILE" in
  549.     none.icm | */none.icm) GAMMAFILE="$ICCTMP.usecie.ps";;
  550.     *)    GAMMAFILE="$ICCTMP.usecie.ps $ICCTMP.crd.ps $ICCTMP.selcrd.ps";;
  551.     esac
  552.     else
  553.     GAMMFILE=
  554.     fi
  555. }
  556.  
  557. if [ $DEBUG -gt 0 ]; then
  558.     ICCTMP=/tmp/icc
  559. else
  560.     ICCTMP=/tmp/icc$$
  561. fi
  562.  
  563. if [ "" = "$COLOR" ]; then
  564.     COLORMODE=
  565.     GAMMAFILE=
  566. else
  567.     case "$COLORMODE" in
  568.     default)    COLORMODE=$DEFAULTCOLORMODE;;
  569.     esac
  570. fi
  571.  
  572. CRDBASE="$PREFIX/share/foo2zjs/crd"
  573. PSFILES="$PREFIX/share/foo2hp/psfiles"
  574. case "$RES" in
  575.     600x600)    SCREEN=screen1200.ps;;
  576.     1200x600)    SCREEN=screen1200.ps;;
  577.     2400x600)    SCREEN=screen2400.ps;;
  578. esac
  579.  
  580. case "$COLORMODE" in
  581. 0|"")
  582.     # Monochrome
  583.     ;;
  584. 10|icm)
  585.     # Use old ICM method
  586.     AIB=-A
  587.     BC=-B
  588.     case "$GAMMAFILE" in
  589.     none.icm | */none.icm)
  590.     create_crd
  591.     ;;
  592.     *.icm|*.ICM|*.icc|*.ICC)
  593.     #
  594.     # Its really an .ICM file, not a gamma file.
  595.     #
  596.     # The file can be a full path name, or the name of a file in $SHARE/icm/
  597.     #
  598.     if [ -r "$GAMMAFILE" ]; then
  599.         create_crd
  600.     elif [ -r "$SHARE/icm/$GAMMAFILE" ]; then
  601.         GAMMAFILE="$SHARE/icm/$GAMMAFILE"
  602.         create_crd
  603.     else
  604.         GAMMAFILE=
  605.     fi
  606.     ;;
  607.     esac
  608.     ;;
  609. *.crd)
  610.     GAMMAFILE="$CRDBASE/prolog.ps"
  611.     if [ -f $COLORMODE ]; then
  612.     GAMMAFILE="$GAMMAFILE $COLORMODE"
  613.     elif [ -f $CRDBASE/$COLORMODE ]; then
  614.     GAMMAFILE="$GAMMAFILE $CRDBASE/$COLORMODE"
  615.     else
  616.     error "Can't find CRD '$COLORMODE' in . or in $CRDBASE"
  617.     fi
  618.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  619.     ;;
  620. *)
  621.     error "Unknown color method '$COLORMODE'"
  622.     ;;
  623. esac
  624.  
  625. if [ "" != "$COLOR" ]; then
  626.     if [ "" = "$AIB" -a "" = "$BC" ]; then
  627.     # Faster, but can't handle AllIsBlack or BlackClears
  628.     : #GSDEV=-sDEVICE=pksmraw
  629.     else
  630.     # Can't handle different size pages
  631.     : #GSDEV=-sDEVICE=bitcmyk
  632.     fi
  633. fi
  634.  
  635. #
  636. #    Figure out USERNAME
  637. #
  638. if [ "$LPUSER" != "" ]; then
  639.     USER="$LPUSER@$LPHOST"
  640. else
  641.     USER=""
  642. fi
  643.  
  644. #
  645. #    Main Program, just cobble together the pipeline and run it
  646. #
  647. #    The malarky with file descriptors 1 and 3 is to avoid a bug in
  648. #    (some versions?) of Ghostscript where Postscript's stdout gets
  649. #    intermingled with the printer drivers output, resulting in
  650. #    corrupted image data.
  651. #
  652. #    CUPS also does grief by adding its own PS code to the input file.
  653. #    We take care of that with the sed command.  Thus, Well Tempered
  654. #    Screening now works!
  655. #
  656. GS="$GSBIN -q -dBATCH -dSAFER -dQUIET -dNOPAUSE"
  657.  
  658. sed 's#^[^/]*cupsPSLevel2#false#' | \
  659. $PREFILTER \
  660. | ($GS $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS \
  661.     -sOutputFile="|cat 1>&3" $GAMMAFILE - >/dev/null 2>&1) 3>&1 \
  662. | foo2hp -r$RES -g$DIM -p$PAPER -m$MEDIA -n$COPIES -d$DUPLEX -s$SOURCE \
  663.         $COLOR -b$BPP $CLIP_UL $CLIP_LR $CLIP_LOG $SAVETONER \
  664.         -J "$LPJOB" -U "$USER" \
  665.         $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD -D$DEBUG
  666.  
  667. #
  668. #    Log the command line, for debugging and problem reports
  669. #
  670. if [ -x /usr/bin/logger ]; then
  671.     logger -t "$BASENAME" -p lpr.info -- \
  672.     "$GSBIN $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPT $GAMAFILE"
  673.     logger -t "$BASENAME" -p lpr.info -- \
  674.     "foo2hp -r$RES -g$DIM -p$PAPER -m$MEDIA \
  675. -n$COPIES -d$DUPLEX -s$SOURCE $COLOR -b$BPP $CLIP_UL $CLIP_LR $CLIP_LOG \
  676. $SAVETONER $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD"
  677. fi
  678.  
  679. #
  680. #    Remove cruft
  681. #
  682. if [ $DEBUG -eq 0 ]; then
  683.     for i in crd.ps log usecie.ps selcrd.ps
  684.     do
  685.     file="$ICCTMP.$i"
  686.     [ -f $file ] && rm -f $file
  687.     done
  688. fi
  689.  
  690. exit 0
  691.